package com.zhangwei.day38.dao;

/**
 * @author zhangwei
 * @version V1.0
 * @Title: Advanced
 * @Package com.zhangwei.day38.dao.UserSqliteOpenHelper
 * @Description:
 * @date 15/10/20 下午2:21
 */

import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.zhangwei.day38.BaseApp;
import com.zhangwei.day38.utils.AppConfig;

/**
 * 接口
 * 接口是实现类
 * Bean
 * Dao工厂
 *
 * 第一步 写一个类继承sqlopenhelper类
 * 1.1>重写构造方法,oncreate() onupgrade()三个方法
 * 第二步 通过SQLiteOpenHelper的实例获得SqliteDatabase
 * 第三步 实现增删改查
 */
public class UserSqliteOpenHelper extends SQLiteOpenHelper {

    public UserSqliteOpenHelper() {
        super(BaseApp.getInstance(), AppConfig.DB_NAME, null, AppConfig.DB_VERSION);
    }

    //创建数据用
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(DbBean.UserDb.CRATE_TAB);
    }


    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if (newVersion > oldVersion) {
            db.execSQL(DbBean.UserDb.DROP_TAB);
            onCreate(db);
        }

    }
}
